package com.usermanage.ServiceImpl;

import com.usermanage.Mapping.SequenceMapping;
import com.usermanage.Service.SequenceService;
import com.usermanage.beanParam.SequenceBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by 過客 on 2018/3/9
 */
@Service("sequenceService")
public class SequenceServiceImpl implements SequenceService {

    @Resource
    private SequenceMapping sequenceMapping;


    @Override
    public String getSequenceNum(String code) {
        return sequenceMapping.getSequenceNum(code);
    }

    /**
     * 重置序列号
     *
     * @param code
     */
    @Override
    public void clearCurrentValue(String code) {
        SequenceBean ps = new SequenceBean();
        ps.setName(code);
        Example<SequenceBean> example = Example.of(ps);
        SequenceBean querySequenceBean = sequenceMapping.findOne(example).get();
        querySequenceBean.setCurrent_value(0);
        sequenceMapping.save(querySequenceBean);

    }
}
